﻿using Fuse8.ContentManagementFramework.Administration.Models;
using Fuse8.ContentManagementFramework.Domain;
using Fuse8.DomainFramework.Common.Locator;
using System;

namespace Fuse8.ContentManagementFramework.Administration.Logic
{
    public static class FileViewFactory
    {
        static FileViewFactory()
        {
            if (!DependencyServiceLocator.Current.IsDefaultServiceRegistered<CmsTemplate>())
            {
                DependencyServiceLocator.Current.SetDefaultService<IFileViewProvider<CmsTemplate>>(new CmsTemplateFileViewProvider());
            }

            if (!DependencyServiceLocator.Current.IsDefaultServiceRegistered<CmsPage>())
            {
                DependencyServiceLocator.Current.SetDefaultService<IFileViewProvider<CmsPage>>(new CmsPageTreeViewProvider());
            }
        }

        public static CmsAdminFileItem GetRoot<T>(int? id)
        {
            IFileViewProvider<T> provider = DependencyServiceLocator.Current.GetInstance<IFileViewProvider<T>>();

            return provider != null ? provider.GetRoot(id) : null;
        }
    }
}